package com.sk.commonadapter_android.adapter;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;

/**
 * @Author yemao
 * @Email yrmao9893@163.com
 * @Date 2017/6/12
 * @Des null!
 */

public class CommonViewHolder extends RecyclerView.ViewHolder {
    private Context mContext;
    private View mContentView;
    private SparseArray<View> mIdData;

    public CommonViewHolder(View itemView) {
        super(itemView);
        this.mContext = itemView.getContext();
        this.mContentView = itemView;
        mIdData = new SparseArray<>();
    }

    public <T extends View> T getView(@IdRes int viewId) {
        View mView = mIdData.get(viewId);
        if (mView == null)
            mView = mContentView.findViewById(viewId);
        return (T) mView;
    }

    public void setTextView(@IdRes int viewId, String value) {
        TextView mTextview = getView(viewId);
        mTextview.setText(value);
    }

}
